/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

/* eslint-disable import/no-extraneous-dependencies */
import React, { useState } from 'react';
import { connect } from 'dva';
import { Form } from 'antd';


import DispatStatisticsList from './DispatStatisticsList';
import DispatStatisticsDetail from './DispatStatisticsDetail';

const DispatStatistics = () => {
  const [pageMode, setpageMode] = useState('list');
  const [detailRecord, setDetailRecord] = useState({});

  const onChangeMode = record => {
    const { id } = record || {};
    setDetailRecord(record);
    setpageMode(id ? 'detail' : 'list');
  };

  return pageMode === 'list' ? (
    <DispatStatisticsList onChangeMode={onChangeMode} />
  ) : (
    <DispatStatisticsDetail onChangeMode={onChangeMode} detailRecord={detailRecord} />
  );
};

export default connect(({ loading }) => ({
  loading,
}))(React.memo(Form.create()(DispatStatistics)));
